package cn.tkd.client.gold.utils;

import cn.tkd.client.gold.context.TkdSystemContext;

import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.URL;

/**
 * 所有远程请求集散地
 * 
 * @author 嘉陵江里捉鱼
 */
public class Request {

	public static RequestBuilder getSellerBuilder() {
		String url = "/gwt_seller/";
		if (TkdSystemContext.isDoingExpress) {//通过html表单的值标示是否读取在途的快递订单
			url = url + "?doing_express=doing_express";
		}
		return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
	}

	public static RequestBuilder getBuyerBuilder() {
		String url = "/gwt_buyer/";
		return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
	}

	public static RequestBuilder getAgents() {
		String url = "/gwt_seller/agent";
		return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
	}

	public static RequestBuilder getCharts() {
		String url = "/chart/data";
		return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
	}

	public static RequestBuilder saveNo(boolean isSeller, String orderId,
			String agentId, String no) {
		if (isSeller) {
			return sellerSaveNo(orderId, agentId, no);
		}
		return buyerSaveNo(orderId, agentId, no);
	}

	private static RequestBuilder sellerSaveNo(String orderId, String agentId,
			String no) {
		String url = "/gwt_seller/saveno?agent_id=" + agentId + "&no_code="
				+ no + "&order_id=" + orderId;
		return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
	}

	private static RequestBuilder buyerSaveNo(String orderId, String agentId,
			String no) {
		String url = "/gwt_buyer/saveno?agent_id=" + agentId + "&no_code=" + no
				+ "&order_id=" + orderId;
		return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
	}
}
